/**
 * 
 * @authors Riche
 * @date    2016-07-05 10:39:22
 * @version 1.1.0
 */

/*Vue.transition('fade', {
    enterClass: 'fadeInLeft',
    leaveClass: 'hide'
});*/

var vm=new Vue({
  el:"#app",
  data:{
    isLoading:true,
    pageSize:PAGESIZE,
    pageIndex:1,

    RankingList:[],
    reqOut: false //判断请求数据是否已完
  },
  compiled: function(){
    var _self = this;
    _self.loadPhoto();
    $(document).scroll(function () {
      var docHeight = $(document).height(),
          winHeight = $(window).height();
      if ((docHeight > winHeight)&&($(document).scrollTop() >= docHeight - winHeight)) {
          if (!_self.reqOut) {
              _self.reqOut = true;
              var str = '<img class="loading-img" src="images/loading.gif"></img>';
              myLoad.pullLoad('quesCont', str);
              _self.loadlist(_self.tabs);

          }
      }
    });

    _self.loadlist();
  },
  methods:{
    loadlist:function(){
      var _self = this;
      var vModal,target;  //用来储存不同的tab页面对应的对象
      var url = 'user_getRankingList';
      var data = {
        pageSize:_self.pageSize,
        pageIndex:_self.pageIndex
      }; 

      vModal = _self;
      target = _self.RankingList;

      if(!vModal.isLoading) return;
      data = Common.jsonEncode(data);
      Common.ajaxCall({ url: url, datatype: 'json', type: 'post', data: data}, function (data) {
          if(data.error_code==0 && data.data.length > 0){
              if(vModal.pageIndex==1){
                target.length = 0;
              }
              for(var i = 0; i < data.data.length; i++){
                target.push(data.data[i]);
              }
              _self.reqOut = false;

              //实际数据与请求的数据量比较
              if (data.data.length >= vModal.pageSize) {
                  myLoad.pullHide(); //加载后，把效果去掉
              } else {
                  _self.reqOut = true;
                  myLoad.noDate(); //暂无数据
                  vModal.isLoading = false;
              }
          }else{
              _self.reqOut = true;
              myLoad.noDate(); //暂无数据
              vModal.isLoading = false;
          }

          vModal.pageIndex++;
      });
      
    },
    loadPhoto:function(){
        myJS.imgScale('.j_1', '1', '1');
        myJS.imgScale('.j_1511', '15', '11');
        myJS.ImgFull('.loadImg','images/liby.png');
    }
  },
  watch:{
    "willShow,RankingList,exchangeList": function(){
        this.loadPhoto();
    }
  }
});